// 获取应用实例
const app = getApp()
const backgroundAudioManager = wx.getBackgroundAudioManager()

Page({
	data: {
		img_src:app.globalData.img_src,
		video_src:app.globalData.video_src,
		show:true,
		videoshow:false,
		videoshow3:false,
		video2show:false,
		buttonshow:true,
		clickable:true,
		autoplay:false
	},
	onLoad(){
		// this.getSystemInfo()
		wx.hideHomeButton()
		this.setData({
			videoshow:true
		})
		//检测版本更新
		const updateManager = wx.getUpdateManager()
		updateManager.onCheckForUpdate(function (res) {
			// 请求完新版本信息的回调
			console.log(res.hasUpdate)
		})

		updateManager.onUpdateReady(function () {
			wx.showModal({
				title: '更新提示',
				content: '新版本已经准备好，是否重启应用？',
				success: function (res) {
					if (res.confirm) {
						// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
						updateManager.applyUpdate()
					}
				}
			})
		})

		updateManager.onUpdateFailed(function () {
			// 新版本下载失败
		})
		this.login()
		console.log(app.globalData)
		setTimeout(()=>{
			this.backmusic()
		},1000)
	},
	backmusic(){
		this.player()
	},
	player() {
		backgroundAudioManager.title = 'Mozart String Quartet No 22 in B-flat major K589 4 Allegro assai'
		backgroundAudioManager.src = 'https://ikea.uglobal.com.cn/guerlainmemberday/Mozart.mp3'
		backgroundAudioManager.onEnded(() => {
			this.player();
		})
	},
	onReady(){
		// setTimeout(function(){
		// 	backgroundAudioManager.stop()
		// 	backgroundAudioManager.title = 'Mozart String Quartet No 22 in B-flat major K589 4 Allegro assai'
		// 	backgroundAudioManager.src = 'https://ikea.uglobal.com.cn/guerlainmemberday/Mozart.mp3'
	
		// 	backgroundAudioManager.play()
		// },1000)		
	},

	login(){
		var that = this;
		wx.login({
     
      success: res => {
        console.log(res.code);
        wx.request({
          url: app.globalData.apiurl+'code2session.php', 
          header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          data: {
            code: res.code
          },
          dataType:"json",
          method:"POST",
          success (res) {
              if(res.data.status == 1){
								app.globalData.userInfo = res.data.data;
								wx.setStorageSync('memberinfo', res.data.data);
								if(res.data.data.mobile){
									that.setData({
										buttonshow:false
									})
								}
              }else{
                wx.showToast({
                  title: res.data.info,
									icon:'none',
									duration:1500
                })
              }
          }
        })
      }
    })
	},
	ended(e) {
		console.log('此播放已结束')
		// this.setData({
		// 	show:true
		// })
		this.setData({
			 videoshow:false
		
		})
		
	},
	  /**
   * 获取分辨率 
   */
  // getSystemInfo() {
  //   const info = wx.bing.getSystemInfo()
  //   let contentBoxHeight = 1200
  //   if (info.windowHeight > 1300 && info.windowHeight < 1500) {
  //     contentBoxHeight = 1400
  //   }
  //   this.setData({
  //     windowHeight: info.windowHeight,
  //     windowHeightsale: info.windowHeightSale,
  //     contentBoxHeight: contentBoxHeight,
  //     s900:info.s900,
  //     scrollPage:info.scrollPage
  //   })
  // },

	getPhoneNumber (e) {
		if(this.data.clickable == false){
			return false;
		}
		this.setData({clickable:false})
   	var that = this;
		setTimeout(function(){
			that.setData({clickable:true})
		},2000)
		var userinfo=wx.getStorageSync('memberinfo');
    var data = {
      openid: userinfo.openid,
      encryptedData:e.detail.encryptedData,
      iv:e.detail.iv
		};
		wx.request({
			url: app.globalData.apiurl+'code2mobile.php', 
			header: {
				"Content-Type": "application/x-www-form-urlencoded"
			},
			data: data,
			method:"POST",
			success (res) {
					if(res.data.status == "1"){
						wx.setStorageSync('memberinfo',res.data.data);
						// var videoplay2 = wx.createVideoContext('myVideo2')
						// videoplay2.play()
						that.setData({
							show:false,
							video2show:true
						})
					}else{
						wx.showToast({
							title: res.data.info,
							icon:'none',
							duration:1500
						})
					}
			}
		})
	},
	
	startBtn:function(e){
		
		// wx.navigateTo({
		// 	url: '/pages/share/share'
		// })
		// return;
		// 1224 streeeeeeeeeeeeeeeeeeeeeeee8.05
		
		// backgroundAudioManager.pause()
		var videoplay2 = wx.createVideoContext('myVideo2')
		console.log(videoplay2)
		videoplay2.stop();
    videoplay2.pause();
		videoplay2.play();
		// backgroundAudioManager.play()
	console.log("1111")
		this.setData({
			show:false,
		 video2show:true,
		 autoplay:true
	 })
	},
	ended2(e) {
		var userinfo=wx.getStorageSync('memberinfo');
		if(userinfo.iscounter||(userinfo.member_level!=="帝王黑卡"&&userinfo.member_level!="蜂姿金卡"&&userinfo.member_level!="兰花钻卡")){
			wx.redirectTo({
				url: '/pages/cardinfo/cardinfo'
			})
		}else{
			wx.redirectTo({
				url: '/pages/game/game'
			})
		}
		
	}
	
	
})

